// pages/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 键名：键值
    imgList:[
      "../../image/swiper1.jpg",
      "../../image/swiper2.jpg",
      "../../image/swiper3.jpg",
      "../../image/swiper4.jpg",
    ],
    // 轮播图的高度
    hei:"",
    // 列表图片
    list:[
      "../../image/list1.png",
      "../../image/list2.png",
      "../../image/list3.png",
      "../../image/list4.png",
      "../../image/list5.png",
      "../../image/list6.png",
      "../../image/list7.png",
      "../../image/list8.png",
      "../../image/list9.png",
      "../../image/list10.png",
    ],
    // 模块数据
    modeList:[
      // 手机
      {
        titleImg:"../../image/phone.jpg",
        text:"更多小米手机产品 >",
        goodsList:[
          {
            id:1,
            img:"../../image/phone1.jpg",
            title:"Redmi K30 4G",
            desc:"120Hz流速屏，全速热爱",
            price:1299,
            other:"起",
            oldPrice:"￥1699",
            num:1,
            checked:true,
          },
          {
            id:2,
            img:"../../image/phone2.jpg",
            title:"Redmi K30 5G",
            desc:"双模5G，120Hz流速屏",
            price:1599,
            other:"起",
            oldPrice:"￥2299",
            num:1,
            checked:true,
          },
          {
            id:3,
            img:"../../image/phone3.jpg",
            title:"Note 8 Pro",
            desc:"6400万全场景四摄",
            price:1099,
            other:"起",
            oldPrice:"￥1399",
            num:1,
            checked:true,
          },
          {
            id:4,
            img:"../../image/phone4.jpg",
            title:"Redmi K30 4G",
            desc:"千元4800万四摄",
            price:899,
            other:"起",
            oldPrice:"￥999",
            num:1,
            checked:true,
          }
        ]
      },
      {
        titleImg:"../../image/tv.jpg",
        text:"更多小米电视产品 >",
        goodsList:[
          {
            id:1,
            img:"../../image/tv1.jpg",
            title:"小米电视4A 65英寸",
            desc:"4K HDR，人工智能语音系统",
            price:2799,
            other:"起",
            oldPrice:"￥2899",
            num:1,
            checked:true,
          },
          {
            id:2,
            img:"../../image/tv2.jpg",
            title:"小米电视4X 43英寸",
            desc:"FHD全高清屏，人工智能语音",
            price:1349,
            other:"起",
            oldPrice:"￥1399",
            num:1,
            checked:true,
          },
          {
            id:3,
            img:"../../image/tv3.jpg",
            title:"小米电视4C 50英寸",
            desc:"4K HDR，钢琴烤漆",
            price:1999,
            other:"",
            oldPrice:"",
            num:1,
            checked:true,
          },
          {
            id:4,
            img:"../../image/tv4.jpg",
            title:"小米电视4C 55英寸",
            desc:"4K HDR，人工智能系统",
            price:2299,
            other:"",
            oldPrice:"",
            num:1,
            checked:true,
          },
          {
            id:5,
            img:"../../image/tv5.jpg",
            title:"小米电视4A 32英寸",
            desc:"人工智能系统，高清液晶屏",
            price:999,
            other:"",
            oldPrice:"",
            num:1,
            checked:true,
          },
          {
            id:6,
            img:"../../image/tv6.jpg",
            title:"小米电视4A 50英寸",
            desc:"4K HDR，人工智能语音系统",
            price:1999,
            other:"",
            oldPrice:"",
            num:1,
            checked:true,
          }
        ]
      }
    ],
    // 屏幕宽度
    winWid:""
  },
  
  // 获取图片自适应高度
  imgH:function(event){
    console.log(event)
    // 图片自身的宽高
    var imgWid = event.detail.width
    var imgHei = event.detail.height
    //console.log(imgWid)
    //console.log(imgHei)
    // 获取屏幕的宽度
    var winWid = wx.getSystemInfoSync().windowWidth
    //console.log(winWid)
    // 自适应的图片高度
    var winHei = winWid / imgWid * imgHei
    // console.log(winHei)
    this.setData({
      hei:winHei,
      winWid:winWid
    })
  },

  // 点击立即购买，跳转到详情页
  toDetails:function(event){
    // console.log(event)
    // 获取模块的下标值
    var modeIndex = event.target.dataset.modeindex
    // 获取具体数据的下标值
    var goodIndex = event.target.dataset.goodindex
    // console.log('modeIndex==>',modeIndex)
    // console.log('goodIndex==>',goodIndex)
    // 获取当前点击的商品数据
    var good = this.data.modeList[modeIndex].goodsList[goodIndex]
     // console.log(good)
     // 设置详情页的缓存数据
     wx.setStorageSync('detailsList', good)
     // 跳转到详情页
     wx.navigateTo({
       url: '/pages/details/details',
     })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 数据缓存
    // 同步
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})